
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_ahj_app/base/pluglin/wxplulin/WxJumpUtils.dart';
import 'package:flutter_ahj_app/base/utils/ShowFiles/GetImageWidget.dart';
import 'package:flutter_ahj_app/base/utils/ToastUtils.dart';
import 'package:flutter_ahj_app/base/values/SQColor.dart';

import 'package:url_launcher/url_launcher.dart';

import '../utils/screen_util.dart';
/*
* 催办
* */
class ShowQueRenDialogDialog extends Dialog{
  var dataScoure;
  Function(Map data) state;
  var checkFzr;
  var checkOther;
  var textName="";
  ShowQueRenDialogDialog(this.dataScoure,this.state,this.checkFzr,this.checkOther,this.textName);
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Material(

      type: MaterialType.transparency,
      child: new Center(

        //保证控件居中效果
        child: new SizedBox(

          width: ScreenUtil.getScreenW(context)*4/5,
          height:400.0,
          child:Container(
            padding: EdgeInsets.fromLTRB(24, 0, 24, 12),
            decoration: BoxDecoration(
              //背景
              color:SQColor.white,
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
              // //设置四周边框
              // border: new Border.all(width: 1, color: Colors.red),
            ),
            child:  Column(children: [
              SizedBox(height: 12,),

              SizedBox(height: 8,),
              Container(
                child: Text("-培训催办通知-",style: TextStyle(color: Color(0xFF333333),fontSize: 18,fontWeight: FontWeight.w700),),
              ),
              SizedBox(height: 36,),
              GestureDetector(
                onTap: (){
                  if(checkFzr){
                    checkFzr=false;
                  }else{
                    checkFzr=true;
                  }
                  state({"type":"1","checked":checkFzr});
                  // state((){});
                },
                child: Row(
                  children: [
                    checkFzr? Icon(
                      Icons.check_circle,
                      size: 25.0,
                      color:Color(0xff165DFF),
                    ):Icon(
                      Icons.panorama_fish_eye,
                      size: 25.0,
                      color:  Color(0xFFAAAAAA),
                    ),

                    SizedBox(width: 8,),
                    Text("企业安全负责人",style: TextStyle(color: Color(0xFF333333),fontSize: 16))
                  ],
                ),
              ),
              SizedBox(height: 16,),

              checkFzr? Container(
                width: ScreenUtil.getScreenW(context)*4/5,

                padding: EdgeInsets.fromLTRB(32, 12, 12, 12),
                decoration: BoxDecoration(
                  //背景
                  color: Color(0xFFF5F7F9),
                  //设置四周圆角 角度
                  borderRadius: BorderRadius.all(Radius.circular(2.0)),
                  // //设置四周边框
                  // border: new Border.all(width: 1, color: Colors.red),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '${dataScoure['safePrincipal'] ?? ''}    ${dataScoure['safePrincipalPhone'] ?? ''}',
                      style: const TextStyle(color: Color(0xFF333333),fontSize: 16),
                    ),
                  ],
                ),

              ):Container(),
              SizedBox(height: 12,),
              // Divider(),
              GestureDetector(
                onTap: (){
                  if(checkOther){
                    checkOther=false;
                  }else{
                    checkOther=true;
                  }
                  state({"type":"2","checked":checkOther});
                },
                child: Row(
                  children: [
                    checkOther? Icon(
                      Icons.check_circle,
                      size: 25.0,
                      color:Color(0xff165DFF),
                    ):Icon(
                      Icons.panorama_fish_eye,
                      size: 25.0,
                      color:  Color(0xFFAAAAAA),
                    ),

                    SizedBox(width: 8,),
                    Text("其他人员",style: TextStyle(color: Color(0xFF333333),fontSize: 16))
                  ],
                ),
              ),
              SizedBox(height: 16,),

              checkOther? Container(
                padding: EdgeInsets.fromLTRB(32, 0, 0, 0),

                // padding: EdgeInsets.all(12),
                decoration: BoxDecoration(
                  //背景
                  color: Color(0xFFF5F7F9),
                  //设置四周圆角 角度
                  borderRadius: BorderRadius.all(Radius.circular(2)),
                  // //设置四周边框
                  // border: new Border.all(width: 1, color: Colors.red),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    TextField(controller: TextEditingController.fromValue(TextEditingValue(
                    // 设置内容
                    text: textName,
                    // 保持光标在最后
                    selection: TextSelection.fromPosition(TextPosition(
                        affinity: TextAffinity.downstream,
                        offset: textName.length)))
              ),decoration: InputDecoration(

                        border: InputBorder.none,
                        contentPadding: EdgeInsets.all(0)

                    ),
                      inputFormatters: [
                        FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))//设置只允许输入数字
                      ],
                    maxLength: 11,
                      onChanged: (value){
                        state({"type":"3","value":value});
                      },
                    )
                  ],
                ),

              ):Container(),
              // Divider(),
              Expanded(child: Container(),flex: 1,),
              Container(
                margin: EdgeInsets.fromLTRB(24, 0, 24, 0),
                height: 48,
                child: Row(
                  children: [
                    Expanded(
                      child: GestureDetector(
                        onTap: (){
                          var data=[];

                          if(checkFzr){
                            data.add({
                              "name":dataScoure['safePrincipal'],
                              "phone":dataScoure['safePrincipalPhone']
                            });
                          }

                          if(checkOther){

                            if(textName!=""){
                              String regexPhoneNumber ="^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[0-9])|(147,145))\\d{8}\$";

                              if(RegExp(regexPhoneNumber).hasMatch(textName)){
                                data.add({
                                  "name":"",
                                  "phone":textName
                                });
                              }else{
                                ToastUtils.showToast("请先填写正确的电话号码");
                                return;
                              }

                            }else{

                              ToastUtils.showToast("请先填写电话号码");

                              return;
                            }


                          }




                         if(data.isEmpty){//没有数据
                           ToastUtils.showToast("请先选择发送人");
                           return;
                         }else{

                           Navigator.pop(context,jsonEncode(data));
                         }
                        },
                        child:Container(
                          decoration: BoxDecoration(
                            //背景
                            color:Color(0xff165DFF),
                            //设置四周圆角 角度
                            borderRadius: BorderRadius.all(Radius.circular(2.0)),
                            // //设置四周边框
                            // border: new Border.all(width: 1, color: Colors.red),
                          ),
                          alignment: Alignment.center,
                          child: Text("发送",style: TextStyle(color:Colors.white,fontSize: 16)),
                        ) ,
                      ),
                    ),

                  ],
                ),
              ),

            ],
            ),
          ),
        ),
      ),
    );
  }

}